import Vue from "vue";
import Vuex from "vuex";
import { storage } from "@/plugins/storage";
import * as types from "./mutation-types";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    access_token: "",
    payInfo: {}
  },
  mutations: {
    [types.SET_ACCESS_TOKEN](state, session) {
      storage.set(
        types.ACCESS_TOKEN,
        session.access_token,
        parseInt(session.expires_in) * 1000
      );
      state.access_token = session.access_token;
    },
    [types.SET_PAY_INFO](state, info) {
      storage.set(
          types.PAY_INFO,
          info
      );
      state.payInfo = info;
    },
    [types.REMOVE_ALL](state) {
      state.access_token = "";
      storage.clear();
    }
  },
  getters: {},
  actions: {
  },
  modules: {}
});
